package term.dept.course.section;

import java.util.HashMap;
import java.util.Map;


/**
 * Contains instructor information with reference to their current sections.
 * @author SJP
 *
 */
public class Instructor {
	
	/**
	 * Static collection of all current Instructors
	 */
	private static HashMap<String,Instructor> insts = new HashMap<String,Instructor>();
	/**
	 * First Name
	 */
	private String first;
	
	/**
	 * Middle Initial
	 */
	private char mid;
	
	/**
	 * Last Name
	 */
	private String last;
	
	/**
	 * This instructors sections
	 */
	private Map<String,Section> curSections;

	/**
	 * Create a new Instructor
	 * @param fn first name
	 * @param mi middle initial
	 * @param ln last name
	 */
	private Instructor(String fn, char mi, String ln){
		first = fn;
		mid = mi;
		last = ln;
		curSections = new HashMap<String,Section>();
	}
	
	private Instructor(String fn, String ln){
		this(fn,' ',ln);
	}
	
	private Instructor(String ln) {
		this("",' ',ln);
	}
	
	private Instructor(){
		this("",' ',"TBD");
	}
	
	/**
	 * Used to retrieve an existing instructor or
	 * create a new one.
	 * @param ln last name of the instructor
	 * @return an Instructor object representing this instructor.
	 */
	public static Instructor get(String ln) {
		if (insts.containsKey(ln))
			return insts.get(ln);
		
		else {
			Instructor i = new Instructor("",' ',ln);
			insts.put(ln, i);
			return i;
		}
	}
	
	/**
	 * @return the full instructor's name
	 */
	public String getName() {
		String out = first + " ";
		if (mid != ' ')
			out += mid + " ";
		out += last;
		return out;
	}
	
	/**
	 * @return the map containing this instructor's current sections
	 */
	public Map<String,Section> getSections() {return curSections;}
	
	/**
	 * Adds a new section to this instructor's current sections.
	 * @param s the new section to add
	 * @return the new section that was added
	 */
	public Section addSection(Section s) {
		curSections.put(s.getID(), s);
		return s;
	}
	
	/**
	 * TODO
	 */
	public void termRollover() {
		//todo
	}

}
